package com.itheima;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
 * @author 黑马程序员
 * @Company http://www.ithiema.com
 * @Version 1.0
 */
public class POIRead2 {
    public static void main(String[] args) throws Exception{
        //1.获取工作薄对象【execl】
        XSSFWorkbook workbook = new XSSFWorkbook("C:\\Users\\sun\\Desktop\\test.xlsx");
        //2. 获取工作表
        XSSFSheet sheet = workbook.getSheetAt(0);
        //3. 获取行对象
        for (Row row : sheet) {
            for (Cell cell : row) {
                if(cell.getCellType() == Cell.CELL_TYPE_NUMERIC){
                    //设置单元格格式为字符串
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                }
                System.out.println(cell.getStringCellValue());
            }
        }
    }
}
